libxc: convert evtchn interfaces to use an opaque handle type
authorIan Campbell <ian.campbell@citrix.com>
Thu, 23 Dec 2010 15:25:57 +0000 (15:25 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 23 Dec 2010 15:25:57 +0000 (15:25 +0000)
This makes the interface consistent with the changes made to the main
interface in 21483:779c0ef9682c.

Also fix some references to "struct xc_interface" which should have
been simply "xc_interface" in tools/xenpaging, and update QEMU_TAG to
pull in the corresponding qemu change.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
30 files changed:
Config.mk
tools/console/daemon/io.c
tools/fs-back/fs-backend.c
tools/fs-back/fs-backend.h
tools/libxc/xc_dom_elfloader.c
tools/libxc/xc_domain_restore.c
tools/libxc/xc_linux.c
tools/libxc/xc_minios.c
tools/libxc/xc_netbsd.c
tools/libxc/xc_private.c
tools/libxc/xc_private.h
tools/libxc/xc_solaris.c
tools/libxc/xc_suspend.c
tools/libxc/xenctrl.h
tools/libxc/xenguest.h
tools/libxl/libxl_dom.c
tools/misc/xen-hptool.c
tools/python/xen/lowlevel/checkpoint/checkpoint.h
tools/python/xen/lowlevel/checkpoint/libcheckpoint.c
tools/xcutils/xc_save.c
tools/xenmon/xenbaked.c
tools/xenpaging/mem_event.h
tools/xenpaging/policy_default.c
tools/xenpaging/xc.c
tools/xenpaging/xc.h
tools/xenpaging/xenpaging.c
tools/xenstore/xenstored_core.c
tools/xenstore/xenstored_domain.c
tools/xenstore/xenstored_domain.h
tools/xentrace/xentrace.c

index 347dd468d220e5bdaa7318cb47a62ac9d57e63da..6cde101f28f93227c46973b0798196785b33939b 100644 (file)
--- a/Config.mk
+++ b/Config.mk
@@ -185,9 +185,9 @@ endif
 # CONFIG_QEMU ?= ../qemu-xen.git
 CONFIG_QEMU ?= $(QEMU_REMOTE)
 
-QEMU_TAG ?= 47a25c461b6b5ab67397f7bbb209590a0839e213
-# Thu Dec 16 15:50:06 2010 +0000
-# stubdom: fix stubdom build following dd9d12dc
+QEMU_TAG ?= b7754ca4a80e9a53b848796c860d19d6fa7a6d08
+# Thu Dec 23 15:21:52 2010 +0000
+# qemu-xen: update for libxc evtchn interface change
 
 # Optional components
 XENSTAT_XENTOP     ?= y
index 4b7f58f4a0969bd879b739da4507a8b43a9848c7..b6d41de99cf6e8190c42bb138aac9e6886015b73 100644 (file)
@@ -68,7 +68,7 @@ static int log_time_guest_needts = 1;
 static int log_hv_fd = -1;
 static evtchn_port_or_error_t log_hv_evtchn = -1;
 static xc_interface *xch; /* why does xenconsoled have two xc handles ? */
-static int xce_handle = -1;
+static xc_evtchn *xce_handle = NULL;
 
 struct buffer {
        char *data;
@@ -90,7 +90,7 @@ struct domain {
        int ring_ref;
        evtchn_port_or_error_t local_port;
        evtchn_port_or_error_t remote_port;
-       int xce_handle;
+       xc_evtchn *xce_handle;
        struct xencons_interface *interface;
        int event_count;
        long long next_period;
@@ -547,13 +547,13 @@ static int domain_create_ring(struct domain *dom)
 
        dom->local_port = -1;
        dom->remote_port = -1;
-       if (dom->xce_handle != -1)
+       if (dom->xce_handle != NULL)
                xc_evtchn_close(dom->xce_handle);
 
        /* Opening evtchn independently for each console is a bit
         * wasteful, but that's how the code is structured... */
-       dom->xce_handle = xc_evtchn_open();
-       if (dom->xce_handle == -1) {
+       dom->xce_handle = xc_evtchn_open(NULL, 0);
+       if (dom->xce_handle == NULL) {
                err = errno;
                goto out;
        }
@@ -564,7 +564,7 @@ static int domain_create_ring(struct domain *dom)
        if (rc == -1) {
                err = errno;
                xc_evtchn_close(dom->xce_handle);
-               dom->xce_handle = -1;
+               dom->xce_handle = NULL;
                goto out;
        }
        dom->local_port = rc;
@@ -574,7 +574,7 @@ static int domain_create_ring(struct domain *dom)
                if (!domain_create_tty(dom)) {
                        err = errno;
                        xc_evtchn_close(dom->xce_handle);
-                       dom->xce_handle = -1;
+                       dom->xce_handle = NULL;
                        dom->local_port = -1;
                        dom->remote_port = -1;
                        goto out;
@@ -655,7 +655,7 @@ static struct domain *create_domain(int domid)
        dom->local_port = -1;
        dom->remote_port = -1;
        dom->interface = NULL;
-       dom->xce_handle = -1;
+       dom->xce_handle = NULL;
 
        if (!watch_domain(dom, true))
                goto out;
@@ -722,9 +722,9 @@ static void shutdown_domain(struct domain *d)
        if (d->interface != NULL)
                munmap(d->interface, getpagesize());
        d->interface = NULL;
-       if (d->xce_handle != -1)
+       if (d->xce_handle != NULL)
                xc_evtchn_close(d->xce_handle);
-       d->xce_handle = -1;
+       d->xce_handle = NULL;
 }
 
 void enum_domains(void)
@@ -933,8 +933,8 @@ void handle_io(void)
                              errno, strerror(errno));
                        goto out;
                }
-               xce_handle = xc_evtchn_open();
-               if (xce_handle == -1) {
+               xce_handle = xc_evtchn_open(NULL, 0);
+               if (xce_handle == NULL) {
                        dolog(LOG_ERR, "Failed to open xce handle: %d (%s)",
                              errno, strerror(errno));
                        goto out;
@@ -994,7 +994,7 @@ void handle_io(void)
                                if (!next_timeout ||
                                    d->next_period < next_timeout)
                                        next_timeout = d->next_period;
-                       } else if (d->xce_handle != -1) {
+                       } else if (d->xce_handle != NULL) {
                                if (discard_overflowed_data ||
                                    !d->buffer.max_capacity ||
                                    d->buffer.size < d->buffer.max_capacity) {
@@ -1055,7 +1055,7 @@ void handle_io(void)
                for (d = dom_head; d; d = n) {
                        n = d->next;
                        if (d->event_count < RATE_LIMIT_ALLOWANCE) {
-                               if (d->xce_handle != -1 &&
+                               if (d->xce_handle != NULL &&
                                    FD_ISSET(xc_evtchn_fd(d->xce_handle),
                                             &readfds))
                                        handle_ring_read(d);
@@ -1083,9 +1083,9 @@ void handle_io(void)
                xc_interface_close(xch);
                xch = 0;
        }
-       if (xce_handle != -1) {
+       if (xce_handle != NULL) {
                xc_evtchn_close(xce_handle);
-               xce_handle = -1;
+               xce_handle = NULL;
        }
        log_hv_evtchn = -1;
 }
index 1737baf9a2ceac587644f2cfa6807d4912c6a3d7..e09a4f70af71cee281c08551de59969cb66f2bab 100644 (file)
@@ -228,9 +228,9 @@ static void handle_connection(int frontend_dom_id, int export_id, char *frontend
         FS_DEBUG("ERROR: failed to write backend node on xenbus\n");
         goto error;
     }
-    mount->evth = -1;
-    mount->evth = xc_evtchn_open(); 
-    if (mount->evth < 0) {
+    mount->evth = NULL;
+    mount->evth = xc_evtchn_open(NULL, 0);
+    if (mount->evth == NULL) {
         FS_DEBUG("ERROR: Couldn't open evtchn!\n");
         goto error;
     }
@@ -289,7 +289,7 @@ error:
         xc_gnttab_close(mount->xch, mount->gnth);
     if (mount->local_evtchn > 0)
         xc_evtchn_unbind(mount->evth, mount->local_evtchn);
-    if (mount->evth > 0)
+    if (mount->evth != NULL)
         xc_evtchn_close(mount->evth);
     if (mount->xch)
         xc_interface_close(mount->xch);
@@ -343,8 +343,8 @@ static void await_connections(void)
                     FD_SET(tfd, &fds);
                     ret = select(tfd + 1, &fds, NULL, NULL, &timeout);
                     if (ret < 0) {
-                        FS_DEBUG("fd %d is bogus, closing the related connection\n", tfd);
-                        pointer->evth = fd;
+                        FS_DEBUG("fd %d is bogus, closing the related connection %p\n", tfd, pointer->evth);
+                        /*pointer->evth = fd;*/
                         terminate_mount_request(pointer);
                         continue;
                     }
index 9ffc9c28544fe811b7f835d2552a2231a4fa283b..37f851cc634aa2188fae115f45b0493b6898defc 100644 (file)
@@ -45,7 +45,7 @@ struct fs_mount
     grant_ref_t grefs[MAX_RING_SIZE];
     evtchn_port_t remote_evtchn;
     xc_interface *xch; /* just for error logging, so a dummy */
-    int evth;                         /* Handle to the event channel */
+    xc_evtchn *evth;               /* Handle to the event channel */
     evtchn_port_t local_evtchn;
     int gnth;
     int shared_ring_size;             /* in pages */
index 9b6a22703cb8434b954d011b2d0b0b8a97bea885..9114bfb333a8a7da97129b46eaf0d74d80ef77cd 100644 (file)
@@ -35,7 +35,7 @@
 
 static void log_callback(struct elf_binary *elf, void *caller_data,
                          int iserr, const char *fmt, va_list al) {
-    struct xc_interface *xch = caller_data;
+    xc_interface *xch = caller_data;
 
     xc_reportv(xch,
           xch->dombuild_logger ? xch->dombuild_logger : xch->error_handler,
@@ -44,7 +44,7 @@ static void log_callback(struct elf_binary *elf, void *caller_data,
                        fmt, al);
 }
 
-void xc_elf_set_logfile(struct xc_interface *xch, struct elf_binary *elf,
+void xc_elf_set_logfile(xc_interface *xch, struct elf_binary *elf,
                         int verbose) {
     elf_set_log(elf, log_callback, xch, verbose);
 }
index f868283059ad3e063fedc608ee1c82c80bdb4f13..d895710a7bffcc4712a0aca3843ea9bb56b3656d 100644 (file)
@@ -49,7 +49,7 @@ struct restore_ctx {
 #define HEARTBEAT_MS 1000
 
 #ifndef __MINIOS__
-static ssize_t rdexact(struct xc_interface *xch, struct restore_ctx *ctx,
+static ssize_t rdexact(xc_interface *xch, struct restore_ctx *ctx,
                        int fd, void* buf, size_t size)
 {
     size_t offset = 0;
index 63b89b4786c9b46e94d176f3f4ec036e1cdf6d12..f2a24c3ab53b35d1d882cb59cbfeb448694be47c 100644 (file)
@@ -68,9 +68,9 @@ int xc_interface_open_core(xc_interface *xch)
     return -1;
 }
 
-int xc_interface_close_core(xc_interface *xch, int fd)
+int xc_interface_close_core(xc_interface *xch)
 {
-    return close(fd);
+    return close(xch->fd);
 }
 
 static int xc_map_foreign_batch_single(xc_interface *xch, uint32_t dom,
@@ -327,42 +327,42 @@ int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
 
 #define DEVXEN "/dev/xen/"
 
-int xc_evtchn_open(void)
+int xc_evtchn_open_core(xc_evtchn *xce)
 {
     return open(DEVXEN "evtchn", O_RDWR);
 }
 
-int xc_evtchn_close(int xce_handle)
+int xc_evtchn_close_core(xc_evtchn *xce)
 {
-    return close(xce_handle);
+    return close(xce->fd);
 }
 
-int xc_evtchn_fd(int xce_handle)
+int xc_evtchn_fd(xc_evtchn *xce)
 {
-    return xce_handle;
+    return xce->fd;
 }
 
-int xc_evtchn_notify(int xce_handle, evtchn_port_t port)
+int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port)
 {
     struct ioctl_evtchn_notify notify;
 
     notify.port = port;
 
-    return ioctl(xce_handle, IOCTL_EVTCHN_NOTIFY, &notify);
+    return ioctl(xce->fd, IOCTL_EVTCHN_NOTIFY, &notify);
 }
 
 evtchn_port_or_error_t
-xc_evtchn_bind_unbound_port(int xce_handle, int domid)
+xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid)
 {
     struct ioctl_evtchn_bind_unbound_port bind;
 
     bind.remote_domain = domid;
 
-    return ioctl(xce_handle, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
+    return ioctl(xce->fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
 }
 
 evtchn_port_or_error_t
-xc_evtchn_bind_interdomain(int xce_handle, int domid,
+xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid,
                            evtchn_port_t remote_port)
 {
     struct ioctl_evtchn_bind_interdomain bind;
@@ -370,42 +370,42 @@ xc_evtchn_bind_interdomain(int xce_handle, int domid,
     bind.remote_domain = domid;
     bind.remote_port = remote_port;
 
-    return ioctl(xce_handle, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
+    return ioctl(xce->fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
 }
 
 evtchn_port_or_error_t
-xc_evtchn_bind_virq(int xce_handle, unsigned int virq)
+xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq)
 {
     struct ioctl_evtchn_bind_virq bind;
 
     bind.virq = virq;
 
-    return ioctl(xce_handle, IOCTL_EVTCHN_BIND_VIRQ, &bind);
+    return ioctl(xce->fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
 }
 
-int xc_evtchn_unbind(int xce_handle, evtchn_port_t port)
+int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port)
 {
     struct ioctl_evtchn_unbind unbind;
 
     unbind.port = port;
 
-    return ioctl(xce_handle, IOCTL_EVTCHN_UNBIND, &unbind);
+    return ioctl(xce->fd, IOCTL_EVTCHN_UNBIND, &unbind);
 }
 
 evtchn_port_or_error_t
-xc_evtchn_pending(int xce_handle)
+xc_evtchn_pending(xc_evtchn *xce)
 {
     evtchn_port_t port;
 
-    if ( read_exact(xce_handle, (char *)&port, sizeof(port)) == -1 )
+    if ( read_exact(xce->fd, (char *)&port, sizeof(port)) == -1 )
         return -1;
 
     return port;
 }
 
-int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
+int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port)
 {
-    return write_exact(xce_handle, (char *)&port, sizeof(port));
+    return write_exact(xce->fd, (char *)&port, sizeof(port));
 }
 
 /* Optionally flush file to disk and discard page cache */
index 146816b1d3943f09648d969e60bacf6833ad887f..c8b0007ce6ad24b47be6083b8641b2cd2f433e9b 100644 (file)
@@ -44,6 +44,9 @@ void minios_interface_close_fd(int fd);
 void minios_evtchn_close_fd(int fd);
 void minios_gnttab_close_fd(int fd);
 
+extern void minios_interface_close_fd(int fd);
+extern void minios_evtchn_close_fd(int fd);
+
 extern struct wait_queue_head event_queue;
 
 int xc_interface_open_core(xc_interface *xch)
@@ -51,9 +54,9 @@ int xc_interface_open_core(xc_interface *xch)
     return alloc_fd(FTYPE_XC);
 }
 
-int xc_interface_close_core(xc_interface *xch, int fd)
+int xc_interface_close_core(xc_interface *xch)
 {
-    return close(fd);
+    return close(xch->fd);
 }
 
 void minios_interface_close_fd(int fd)
@@ -169,7 +172,7 @@ int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
     return call.result;
 }
 
-int xc_evtchn_open(void)
+int xc_evtchn_open_core(xc_evtchn *xce)
 {
     int fd = alloc_fd(FTYPE_EVTCHN), i;
     for (i = 0; i < MAX_EVTCHN_PORTS; i++) {
@@ -180,9 +183,9 @@ int xc_evtchn_open(void)
     return fd;
 }
 
-int xc_evtchn_close(int xce_handle)
+int xc_evtchn_close_core(xc_evtchn *xce)
 {
-    return close(xce_handle);
+    return close(xce->fd);
 }
 
 void minios_evtchn_close_fd(int fd)
@@ -194,12 +197,12 @@ void minios_evtchn_close_fd(int fd)
     files[fd].type = FTYPE_NONE;
 }
 
-int xc_evtchn_fd(int xce_handle)
+int xc_evtchn_fd(xc_evtchn *xce)
 {
-    return xce_handle;
+    return xce->fd;
 }
 
-int xc_evtchn_notify(int xce_handle, evtchn_port_t port)
+int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port)
 {
     int ret;
 
@@ -213,144 +216,144 @@ int xc_evtchn_notify(int xce_handle, evtchn_port_t port)
 }
 
 /* XXX Note: This is not threadsafe */
-static int port_alloc(int xce_handle) {
+static int port_alloc(int fd) {
     int i;
     for (i= 0; i < MAX_EVTCHN_PORTS; i++)
-       if (files[xce_handle].evtchn.ports[i].port == -1)
+       if (files[fd].evtchn.ports[i].port == -1)
            break;
     if (i == MAX_EVTCHN_PORTS) {
        printf("Too many ports in xc handle\n");
        errno = EMFILE;
        return -1;
     }
-    files[xce_handle].evtchn.ports[i].pending = 0;
+    files[fd].evtchn.ports[i].pending = 0;
     return i;
 }
 
 static void evtchn_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
 {
-    int xce_handle = (intptr_t) data;
+    int fd = (int)(intptr_t)data;
     int i;
-    assert(files[xce_handle].type == FTYPE_EVTCHN);
+    assert(files[fd].type == FTYPE_EVTCHN);
     mask_evtchn(port);
     for (i= 0; i < MAX_EVTCHN_PORTS; i++)
-       if (files[xce_handle].evtchn.ports[i].port == port)
+       if (files[fd].evtchn.ports[i].port == port)
            break;
     if (i == MAX_EVTCHN_PORTS) {
-       printk("Unknown port for handle %d\n", xce_handle);
+       printk("Unknown port for handle %d\n", fd);
        return;
     }
-    files[xce_handle].evtchn.ports[i].pending = 1;
-    files[xce_handle].read = 1;
+    files[fd].evtchn.ports[i].pending = 1;
+    files[fd].read = 1;
     wake_up(&event_queue);
 }
 
-evtchn_port_or_error_t xc_evtchn_bind_unbound_port(int xce_handle, int domid)
+evtchn_port_or_error_t xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid)
 {
     int ret, i;
     evtchn_port_t port;
 
     assert(get_current() == main_thread);
-    i = port_alloc(xce_handle);
+    i = port_alloc(xce->fd);
     if (i == -1)
        return -1;
 
     printf("xc_evtchn_bind_unbound_port(%d)", domid);
-    ret = evtchn_alloc_unbound(domid, evtchn_handler, (void*)(intptr_t)xce_handle, &port);
+    ret = evtchn_alloc_unbound(domid, evtchn_handler, (void*)(intptr_t)xce->fd, &port);
     printf(" = %d\n", ret);
 
     if (ret < 0) {
        errno = -ret;
        return -1;
     }
-    files[xce_handle].evtchn.ports[i].bound = 1;
-    files[xce_handle].evtchn.ports[i].port = port;
+    files[xce->fd].evtchn.ports[i].bound = 1;
+    files[xce->fd].evtchn.ports[i].port = port;
     unmask_evtchn(port);
     return port;
 }
 
-evtchn_port_or_error_t xc_evtchn_bind_interdomain(int xce_handle, int domid,
+evtchn_port_or_error_t xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid,
     evtchn_port_t remote_port)
 {
     evtchn_port_t local_port;
     int ret, i;
 
     assert(get_current() == main_thread);
-    i = port_alloc(xce_handle);
+    i = port_alloc(xce->fd);
     if (i == -1)
        return -1;
 
     printf("xc_evtchn_bind_interdomain(%d, %"PRId32")", domid, remote_port);
-    ret = evtchn_bind_interdomain(domid, remote_port, evtchn_handler, (void*)(intptr_t)xce_handle, &local_port);
+    ret = evtchn_bind_interdomain(domid, remote_port, evtchn_handler, (void*)(intptr_t)xce->fd, &local_port);
     printf(" = %d\n", ret);
 
     if (ret < 0) {
        errno = -ret;
        return -1;
     }
-    files[xce_handle].evtchn.ports[i].bound = 1;
-    files[xce_handle].evtchn.ports[i].port = local_port;
+    files[xce->fd].evtchn.ports[i].bound = 1;
+    files[xce->fd].evtchn.ports[i].port = local_port;
     unmask_evtchn(local_port);
     return local_port;
 }
 
-int xc_evtchn_unbind(int xce_handle, evtchn_port_t port)
+int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port)
 {
     int i;
     for (i = 0; i < MAX_EVTCHN_PORTS; i++)
-       if (files[xce_handle].evtchn.ports[i].port == port) {
-           files[xce_handle].evtchn.ports[i].port = -1;
+       if (files[xce->fd].evtchn.ports[i].port == port) {
+           files[xce->fd].evtchn.ports[i].port = -1;
            break;
        }
     if (i == MAX_EVTCHN_PORTS) {
-       printf("Warning: couldn't find port %"PRId32" for xc handle %x\n", port, xce_handle);
+       printf("Warning: couldn't find port %"PRId32" for xc handle %x\n", port, xce->fd);
        errno = -EINVAL;
        return -1;
     }
-    files[xce_handle].evtchn.ports[i].bound = 0;
+    files[xce->fd].evtchn.ports[i].bound = 0;
     unbind_evtchn(port);
     return 0;
 }
 
-evtchn_port_or_error_t xc_evtchn_bind_virq(int xce_handle, unsigned int virq)
+evtchn_port_or_error_t xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq)
 {
     evtchn_port_t port;
     int i;
 
     assert(get_current() == main_thread);
-    i = port_alloc(xce_handle);
+    i = port_alloc(xce->fd);
     if (i == -1)
        return -1;
 
     printf("xc_evtchn_bind_virq(%d)", virq);
-    port = bind_virq(virq, evtchn_handler, (void*)(intptr_t)xce_handle);
+    port = bind_virq(virq, evtchn_handler, (void*)(intptr_t)xce->fd);
 
     if (port < 0) {
        errno = -port;
        return -1;
     }
-    files[xce_handle].evtchn.ports[i].bound = 1;
-    files[xce_handle].evtchn.ports[i].port = port;
+    files[xce->fd].evtchn.ports[i].bound = 1;
+    files[xce->fd].evtchn.ports[i].port = port;
     unmask_evtchn(port);
     return port;
 }
 
-evtchn_port_or_error_t xc_evtchn_pending(int xce_handle)
+evtchn_port_or_error_t xc_evtchn_pending(xc_evtchn *xce)
 {
     int i;
     unsigned long flags;
     evtchn_port_t ret = -1;
 
     local_irq_save(flags);
-    files[xce_handle].read = 0;
+    files[xce->fd].read = 0;
     for (i = 0; i < MAX_EVTCHN_PORTS; i++) {
-        evtchn_port_t port = files[xce_handle].evtchn.ports[i].port;
-        if (port != -1 && files[xce_handle].evtchn.ports[i].pending) {
+        evtchn_port_t port = files[xce->fd].evtchn.ports[i].port;
+        if (port != -1 && files[xce->fd].evtchn.ports[i].pending) {
             if (ret == -1) {
                 ret = port;
-                files[xce_handle].evtchn.ports[i].pending = 0;
+                files[xce->fd].evtchn.ports[i].pending = 0;
             } else {
-                files[xce_handle].read = 1;
+                files[xce->fd].read = 1;
                 break;
             }
         }
@@ -359,7 +362,7 @@ evtchn_port_or_error_t xc_evtchn_pending(int xce_handle)
     return ret;
 }
 
-int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
+int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port)
 {
     unmask_evtchn(port);
     return 0;
index c6bf2276842c4a578bf7c1dd7f40d5e4f816918e..f60d0d41549eb0fd079b92caea93fb2ffd10b9ec 100644 (file)
@@ -60,9 +60,9 @@ int xc_interface_open_core(xc_interface *xch)
     return -1;
 }
 
-int xc_interface_close_core(xc_interface *xch, int fd)
+int xc_interface_close_core(xc_interface *xch)
 {
-    return close(fd);
+    return close(xch->fd);
 }
 
 void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
@@ -181,39 +181,39 @@ int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
 
 #define EVTCHN_DEV_NAME  "/dev/xenevt"
 
-int xc_evtchn_open(void)
+int xc_evtchn_open_core(xc_evtchn *xce)
 {
     return open(EVTCHN_DEV_NAME, O_NONBLOCK|O_RDWR);
 }
 
-int xc_evtchn_close(int xce_handle)
+int xc_evtchn_close_core(xc_evtchn *xce)
 {
-    return close(xce_handle);
+    return close(xce->fd);
 }
 
-int xc_evtchn_fd(int xce_handle)
+int xc_evtchn_fd(xc_evtchn *xce)
 {
-    return xce_handle;
+    return xce->fd;
 }
 
-int xc_evtchn_notify(int xce_handle, evtchn_port_t port)
+int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port)
 {
     struct ioctl_evtchn_notify notify;
 
     notify.port = port;
 
-    return ioctl(xce_handle, IOCTL_EVTCHN_NOTIFY, &notify);
+    return ioctl(xce->fd, IOCTL_EVTCHN_NOTIFY, &notify);
 }
 
 evtchn_port_or_error_t
-xc_evtchn_bind_unbound_port(int xce_handle, int domid)
+xc_evtchn_bind_unbound_port(xc_evtchn * xce, int domid)
 {
     struct ioctl_evtchn_bind_unbound_port bind;
     int ret;
 
     bind.remote_domain = domid;
 
-    ret = ioctl(xce_handle, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
+    ret = ioctl(xce->fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
     if (ret == 0)
        return bind.port;
     else
@@ -221,7 +221,7 @@ xc_evtchn_bind_unbound_port(int xce_handle, int domid)
 }
 
 evtchn_port_or_error_t
-xc_evtchn_bind_interdomain(int xce_handle, int domid,
+xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid,
                            evtchn_port_t remote_port)
 {
     struct ioctl_evtchn_bind_interdomain bind;
@@ -230,31 +230,31 @@ xc_evtchn_bind_interdomain(int xce_handle, int domid,
     bind.remote_domain = domid;
     bind.remote_port = remote_port;
 
-    ret = ioctl(xce_handle, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
+    ret = ioctl(xce->fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
     if (ret == 0)
        return bind.port;
     else
        return -1;
 }
 
-int xc_evtchn_unbind(int xce_handle, evtchn_port_t port)
+int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port)
 {
     struct ioctl_evtchn_unbind unbind;
 
     unbind.port = port;
 
-    return ioctl(xce_handle, IOCTL_EVTCHN_UNBIND, &unbind);
+    return ioctl(xce->fd, IOCTL_EVTCHN_UNBIND, &unbind);
 }
 
 evtchn_port_or_error_t
-xc_evtchn_bind_virq(int xce_handle, unsigned int virq)
+xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq)
 {
     struct ioctl_evtchn_bind_virq bind;
     int err;
 
     bind.virq = virq;
 
-    err = ioctl(xce_handle, IOCTL_EVTCHN_BIND_VIRQ, &bind);
+    err = ioctl(xce->fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
     if (err)
        return -1;
     else
@@ -262,19 +262,19 @@ xc_evtchn_bind_virq(int xce_handle, unsigned int virq)
 }
 
 evtchn_port_or_error_t
-xc_evtchn_pending(int xce_handle)
+xc_evtchn_pending(xc_evtchn *xce)
 {
     evtchn_port_t port;
 
-    if ( read_exact(xce_handle, (char *)&port, sizeof(port)) == -1 )
+    if ( read_exact(xce->fd, (char *)&port, sizeof(port)) == -1 )
         return -1;
 
     return port;
 }
 
-int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
+int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port)
 {
-    return write_exact(xce_handle, (char *)&port, sizeof(port));
+    return write_exact(xce->fd, (char *)&port, sizeof(port));
 }
 
 /* Optionally flush file to disk and discard page cache */
index 3b83a8aa5f246a387cd9e09264a79f47b3375f64..4cd89209fa8086ac7e616c784fa110c0edebe872 100644 (file)
 #include <pthread.h>
 #include <assert.h>
 
-xc_interface *xc_interface_open(xentoollog_logger *logger,
-                                xentoollog_logger *dombuild_logger,
-                                unsigned open_flags) {
-    xc_interface xch_buf, *xch = &xch_buf;
+static struct xc_interface_core *xc_interface_open_common(xentoollog_logger *logger,
+                                              xentoollog_logger *dombuild_logger,
+                                              unsigned open_flags,
+                                              enum xc_interface_type type,
+                                              int (*open_core)(struct xc_interface_core *xch))
+{
+    struct xc_interface_core xch_buf, *xch = &xch_buf;
 
+    xch->type = type;
     xch->flags = open_flags;
     xch->fd = -1;
     xch->dombuild_logger_file = 0;
@@ -57,7 +61,7 @@ xc_interface *xc_interface_open(xentoollog_logger *logger,
     *xch = xch_buf;
 
     if (!(open_flags & XC_OPENFLAG_DUMMY)) {
-        xch->fd = xc_interface_open_core(xch);
+        xch->fd = open_core(xch);
         if (xch->fd < 0)
             goto err;
     }
@@ -70,7 +74,7 @@ xc_interface *xc_interface_open(xentoollog_logger *logger,
     return 0;
 }
 
-int xc_interface_close(xc_interface *xch)
+static int xc_interface_close_common(xc_interface *xch, int (*close_core)(struct xc_interface_core *xch))
 {
     int rc = 0;
 
@@ -78,7 +82,7 @@ int xc_interface_close(xc_interface *xch)
     xtl_logger_destroy(xch->error_handler_tofree);
 
     if (xch->fd >= 0) {
-        rc = xc_interface_close_core(xch, xch->fd);
+        rc = close_core(xch);
         if (rc) PERROR("Could not close hypervisor interface");
     }
 
@@ -86,6 +90,31 @@ int xc_interface_close(xc_interface *xch)
     return rc;
 }
 
+xc_interface *xc_interface_open(xentoollog_logger *logger,
+                                xentoollog_logger *dombuild_logger,
+                                unsigned open_flags)
+{
+    return xc_interface_open_common(logger, dombuild_logger, open_flags,
+                                    XC_INTERFACE_PRIVCMD, &xc_interface_open_core);
+}
+
+int xc_interface_close(xc_interface *xch)
+{
+    return xc_interface_close_common(xch, &xc_interface_close_core);
+}
+
+xc_evtchn *xc_evtchn_open(xentoollog_logger *logger,
+                             unsigned open_flags)
+{
+    return xc_interface_open_common(logger, NULL, open_flags,
+                                    XC_INTERFACE_EVTCHN, &xc_evtchn_open_core);
+}
+
+int xc_evtchn_close(xc_evtchn *xce)
+{
+    return xc_interface_close_common(xce, &xc_evtchn_close_core);
+}
+
 static pthread_key_t errbuf_pkey;
 static pthread_once_t errbuf_pkey_once = PTHREAD_ONCE_INIT;
 
index 153458b0fb1e67419f19ea18252d0f62d79f7c78..5cd936cb72ea564848327a007b01829b90b17c15 100644 (file)
 */
 #define MAX_PAGECACHE_USAGE (4*1024)
 
-struct xc_interface {
+enum xc_interface_type {
+       XC_INTERFACE_PRIVCMD,
+       XC_INTERFACE_EVTCHN,
+};
+
+struct xc_interface_core {
+    enum xc_interface_type type;
     int fd;
     int flags;
     xentoollog_logger *error_handler,   *error_handler_tofree;
@@ -257,8 +263,11 @@ static inline int do_sysctl(xc_interface *xch, struct xen_sysctl *sysctl)
 
 int do_memory_op(xc_interface *xch, int cmd, void *arg, size_t len);
 
-int xc_interface_open_core(xc_interface *xch); /* returns fd, logs errors */
-int xc_interface_close_core(xc_interface *xch, int fd); /* no logging */
+int xc_interface_open_core(struct xc_interface_core *xch); /* returns fd, logs errors */
+int xc_interface_close_core(struct xc_interface_core *xch); /* no logging */
+
+int xc_evtchn_open_core(struct xc_interface_core *xce); /* returns fd, logs errors */
+int xc_evtchn_close_core(struct xc_interface_core *xce); /* no logging */
 
 void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom,
                             size_t size, int prot, size_t chunksize,
index b0155e1de436f7bdea8f64b76f5d22a19657452b..40ee6f03ca6f1ca78158f931a295eaf7067cca6a 100644 (file)
@@ -167,7 +167,7 @@ int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
                       (unsigned long)hypercall);
 }
 
-int xc_evtchn_open(void)
+int xc_evtchn_open_core(xc_evtchn *xce)
 {
     int fd;
 
@@ -180,37 +180,37 @@ int xc_evtchn_open(void)
     return fd;
 }
 
-int xc_evtchn_close(int xce_handle)
+int xc_evtchn_close_core(xc_evtchn *xce)
 {
-    return close(xce_handle);
+    return close(xce->fd);
 }
 
-int xc_evtchn_fd(int xce_handle)
+int xc_evtchn_fd(xc_evtchn *xce)
 {
-    return xce_handle;
+    return xce->fd;
 }
 
-int xc_evtchn_notify(int xce_handle, evtchn_port_t port)
+int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port)
 {
     struct ioctl_evtchn_notify notify;
 
     notify.port = port;
 
-    return ioctl(xce_handle, IOCTL_EVTCHN_NOTIFY, &notify);
+    return ioctl(xce->fd, IOCTL_EVTCHN_NOTIFY, &notify);
 }
 
 evtchn_port_or_error_t
-xc_evtchn_bind_unbound_port(int xce_handle, int domid)
+xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid)
 {
     struct ioctl_evtchn_bind_unbound_port bind;
 
     bind.remote_domain = domid;
 
-    return ioctl(xce_handle, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
+    return ioctl(xce->fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
 }
 
 evtchn_port_or_error_t
-xc_evtchn_bind_interdomain(int xce_handle, int domid,
+xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid,
                            evtchn_port_t remote_port)
 {
     struct ioctl_evtchn_bind_interdomain bind;
@@ -218,42 +218,42 @@ xc_evtchn_bind_interdomain(int xce_handle, int domid,
     bind.remote_domain = domid;
     bind.remote_port = remote_port;
 
-    return ioctl(xce_handle, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
+    return ioctl(xce->fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
 }
 
 evtchn_port_or_error_t
-xc_evtchn_bind_virq(int xce_handle, unsigned int virq)
+xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq)
 {
     struct ioctl_evtchn_bind_virq bind;
 
     bind.virq = virq;
 
-    return ioctl(xce_handle, IOCTL_EVTCHN_BIND_VIRQ, &bind);
+    return ioctl(xce->fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
 }
 
-int xc_evtchn_unbind(int xce_handle, evtchn_port_t port)
+int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port)
 {
     struct ioctl_evtchn_unbind unbind;
 
     unbind.port = port;
 
-    return ioctl(xce_handle, IOCTL_EVTCHN_UNBIND, &unbind);
+    return ioctl(xce->fd, IOCTL_EVTCHN_UNBIND, &unbind);
 }
 
 evtchn_port_or_error_t
-xc_evtchn_pending(int xce_handle)
+xc_evtchn_pending(xc_evtchn *xce)
 {
     evtchn_port_t port;
 
-    if ( read_exact(xce_handle, (char *)&port, sizeof(port)) == -1 )
+    if ( read_exact(xce->fd, (char *)&port, sizeof(port)) == -1 )
         return -1;
 
     return port;
 }
 
-int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
+int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port)
 {
-    return write_exact(xce_handle, (char *)&port, sizeof(port));
+    return write_exact(xce->fd, (char *)&port, sizeof(port));
 }
 
 /* Optionally flush file to disk and discard page cache */
index 52e8a33707c672999eec0e9fddd5248aab558291..1ace411860cb9128702bf0ebd5b1369c1cfa41a0 100644 (file)
@@ -75,7 +75,7 @@ static int unlock_suspend_event(xc_interface *xch, int domid)
     return -EPERM;
 }
 
-int xc_await_suspend(xc_interface *xch, int xce, int suspend_evtchn)
+int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn)
 {
     int rc;
 
@@ -94,7 +94,7 @@ int xc_await_suspend(xc_interface *xch, int xce, int suspend_evtchn)
     return 0;
 }
 
-int xc_suspend_evtchn_release(xc_interface *xch, int xce, int domid, int suspend_evtchn)
+int xc_suspend_evtchn_release(xc_interface *xch, xc_evtchn *xce, int domid, int suspend_evtchn)
 {
     if (suspend_evtchn >= 0)
         xc_evtchn_unbind(xce, suspend_evtchn);
@@ -102,7 +102,7 @@ int xc_suspend_evtchn_release(xc_interface *xch, int xce, int domid, int suspend
     return unlock_suspend_event(xch, domid);
 }
 
-int xc_suspend_evtchn_init(xc_interface *xch, int xce, int domid, int port)
+int xc_suspend_evtchn_init(xc_interface *xch, xc_evtchn *xce, int domid, int port)
 {
     int rc, suspend_evtchn = -1;
 
index 48e72153108bc0770b94d574dea9af0e79307e9c..abfeedb582563b8d2d61396612282d4cbfe4f1ac 100644 (file)
  * the callback.
  */
 
-typedef struct xc_interface xc_interface;
+typedef struct xc_interface_core xc_interface;
+typedef struct xc_interface_core xc_evtchn;
 typedef enum xc_error_code xc_error_code;
 
 
@@ -826,38 +827,38 @@ int xc_evtchn_status(xc_interface *xch, xc_evtchn_status_t *status);
  *
  * Before Xen pre-4.1 this function would sometimes report errors with perror.
  */
-int xc_evtchn_open(void);
+xc_evtchn *xc_evtchn_open(xentoollog_logger *logger,
+                             unsigned open_flags);
 
 /*
  * Close a handle previously allocated with xc_evtchn_open().
  */
-int xc_evtchn_close(int xce_handle);
+int xc_evtchn_close(xc_evtchn *xce);
 
 /*
- * Return an fd that can be select()ed on for further calls to
- * xc_evtchn_pending().
+ * Return an fd that can be select()ed on.
  */
-int xc_evtchn_fd(int xce_handle);
+int xc_evtchn_fd(xc_evtchn *xce);
 
 /*
  * Notify the given event channel. Returns -1 on failure, in which case
  * errno will be set appropriately.
  */
-int xc_evtchn_notify(int xce_handle, evtchn_port_t port);
+int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port);
 
 /*
  * Returns a new event port awaiting interdomain connection from the given
  * domain ID, or -1 on failure, in which case errno will be set appropriately.
  */
 evtchn_port_or_error_t
-xc_evtchn_bind_unbound_port(int xce_handle, int domid);
+xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid);
 
 /*
  * Returns a new event port bound to the remote port for the given domain ID,
  * or -1 on failure, in which case errno will be set appropriately.
  */
 evtchn_port_or_error_t
-xc_evtchn_bind_interdomain(int xce_handle, int domid,
+xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid,
                            evtchn_port_t remote_port);
 
 /*
@@ -865,26 +866,26 @@ xc_evtchn_bind_interdomain(int xce_handle, int domid,
  * the VIRQ, or -1 on failure, in which case errno will be set appropriately.
  */
 evtchn_port_or_error_t
-xc_evtchn_bind_virq(int xce_handle, unsigned int virq);
+xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq);
 
 /*
  * Unbind the given event channel. Returns -1 on failure, in which case errno
  * will be set appropriately.
  */
-int xc_evtchn_unbind(int xce_handle, evtchn_port_t port);
+int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port);
 
 /*
  * Return the next event channel to become pending, or -1 on failure, in which
  * case errno will be set appropriately.  
  */
 evtchn_port_or_error_t
-xc_evtchn_pending(int xce_handle);
+xc_evtchn_pending(xc_evtchn *xce);
 
 /*
  * Unmask the given event channel. Returns -1 on failure, in which case errno
  * will be set appropriately.
  */
-int xc_evtchn_unmask(int xce_handle, evtchn_port_t port);
+int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port);
 
 int xc_physdev_pci_access_modify(xc_interface *xch,
                                  uint32_t domid,
@@ -1754,7 +1755,7 @@ int xc_flask_getavc_threshold(xc_interface *xc_handle);
 int xc_flask_setavc_threshold(xc_interface *xc_handle, int threshold);
 
 struct elf_binary;
-void xc_elf_set_logfile(struct xc_interface *xch, struct elf_binary *elf,
+void xc_elf_set_logfile(xc_interface *xch, struct elf_binary *elf,
                         int verbose);
 /* Useful for callers who also use libelf. */
 
index b9d986e20e7022b7890b8aa8bb0e0e37f9551f12..dd0c4cf6e890a147103fca6e1a9a403a72e57f1b 100644 (file)
@@ -173,11 +173,11 @@ int xc_hvm_build_mem(xc_interface *xch,
                      const char *image_buffer,
                      unsigned long image_size);
 
-int xc_suspend_evtchn_release(xc_interface *xch, int xce, int domid, int suspend_evtchn);
+int xc_suspend_evtchn_release(xc_interface *xch, xc_evtchn *xce, int domid, int suspend_evtchn);
 
-int xc_suspend_evtchn_init(xc_interface *xch, int xce, int domid, int port);
+int xc_suspend_evtchn_init(xc_interface *xch, xc_evtchn *xce, int domid, int port);
 
-int xc_await_suspend(xc_interface *xch, int xce, int suspend_evtchn);
+int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn);
 
 int xc_get_bit_size(xc_interface *xch,
                     const char *image_name, const char *cmdline,
index 31b057d6807370659a392022bdbd6a59f60243cd..7e49c5afaf9a90bf79346a2c995ec283f2c3abf6 100644 (file)
@@ -315,7 +315,7 @@ int libxl__domain_restore_common(libxl_ctx *ctx, uint32_t domid,
 
 struct suspendinfo {
     libxl__gc *gc;
-    int xce; /* event channel handle */
+    xc_evtchn *xce; /* event channel handle */
     int suspend_eventchn;
     int domid;
     int hvm;
@@ -419,11 +419,11 @@ int libxl__domain_suspend_common(libxl_ctx *ctx, uint32_t domid, int fd,
     si.gc = &gc;
     si.suspend_eventchn = -1;
 
-    si.xce = xc_evtchn_open();
-    if (si.xce < 0)
+    si.xce = xc_evtchn_open(NULL, 0);
+    if (si.xce == NULL)
         goto out;
-
-    if (si.xce > 0) {
+    else
+    {
         port = xs_suspend_evtchn_port(si.domid);
 
         if (port >= 0) {
@@ -447,7 +447,7 @@ int libxl__domain_suspend_common(libxl_ctx *ctx, uint32_t domid, int fd,
 
     if (si.suspend_eventchn > 0)
         xc_suspend_evtchn_release(ctx->xch, si.xce, domid, si.suspend_eventchn);
-    if (si.xce > 0)
+    if (si.xce != NULL)
         xc_evtchn_close(si.xce);
 
 out:
index cc4d6739f6f55925f5a34513aff01102d6457c4c..374d88315d4e696cf0b468e7a3f5e9ef52e9004a 100644 (file)
@@ -98,7 +98,7 @@ static int hp_mem_query_func(int argc, char *argv[])
 
 extern int xs_suspend_evtchn_port(int domid);
 
-static int suspend_guest(xc_interface *xch, int xce, int domid, int *evtchn)
+static int suspend_guest(xc_interface *xch, xc_evtchn *xce, int domid, int *evtchn)
 {
     int port, rc, suspend_evtchn = -1;
 
@@ -192,10 +192,11 @@ static int hp_mem_offline_func(int argc, char *argv[])
                 }
                 else if (status & PG_OFFLINE_OWNED)
                 {
-                    int result, xce, suspend_evtchn = -1;
-                    xce = xc_evtchn_open();
+                    int result, suspend_evtchn = -1;
+                    xc_evtchn *xce;
+                    xce = xc_evtchn_open(NULL, 0);
 
-                    if (xce < 0)
+                    if (xce == NULL)
                     {
                         fprintf(stderr, "When exchange page, fail"
                                 " to open evtchn\n");
index 24db54faba8dc30a87a1e7f600165b064dd5f683..36455fbf75c1efa06f1ac8b55f6d666001bd7653 100644 (file)
@@ -19,7 +19,7 @@ typedef enum {
 
 typedef struct {
     xc_interface *xch;
-    int xce;               /* event channel handle */
+    xc_evtchn *xce;        /* event channel handle */
     struct xs_handle* xsh; /* xenstore handle */
     int watching_shutdown; /* state of watch on @releaseDomain */
 
index d7fad711de2d0285e2cfe64cfa6d4dbeaf7680c2..f4d3e7fd1a92e5adcb771e37c432dcdf86a78abe 100644 (file)
@@ -48,7 +48,7 @@ char* checkpoint_error(checkpoint_state* s)
 void checkpoint_init(checkpoint_state* s)
 {
     s->xch = NULL;
-    s->xce = -1;
+    s->xce = NULL;
     s->xsh = NULL;
     s->watching_shutdown = 0;
 
@@ -89,8 +89,8 @@ int checkpoint_open(checkpoint_state* s, unsigned int domid)
        return -1;
     }
 
-    s->xce = xc_evtchn_open();
-    if (s->xce < 0) {
+    s->xce = xc_evtchn_open(NULL, 0);
+    if (s->xce == NULL) {
        checkpoint_close(s);
        s->errstr = "could not open event channel handle";
 
@@ -149,9 +149,9 @@ void checkpoint_close(checkpoint_state* s)
     xc_interface_close(s->xch);
     s->xch = NULL;
   }
-  if (s->xce >= 0) {
+  if (s->xce != NULL) {
     xc_evtchn_close(s->xce);
-    s->xce = -1;
+    s->xce = NULL;
   }
   if (s->xsh) {
     xs_daemon_close(s->xsh);
@@ -360,7 +360,7 @@ static int setup_suspend_evtchn(checkpoint_state* s)
 static void release_suspend_evtchn(checkpoint_state *s)
 {
   /* TODO: teach xen to clean up if port is unbound */
-  if (s->xce >= 0 && s->suspend_evtchn >= 0) {
+  if (s->xce != NULL && s->suspend_evtchn >= 0) {
     xc_suspend_evtchn_release(s->xch, s->xce, s->domid, s->suspend_evtchn);
     s->suspend_evtchn = -1;
   }
index 59380c4dbb0819ee9c35333bf3c9155275472186..debb1bb89eadb56f402c3113c1569e74931cfb94 100644 (file)
@@ -25,7 +25,7 @@
 
 static struct suspendinfo {
     xc_interface *xch;
-    int xce; /* event channel handle */
+    xc_evtchn *xce; /* event channel handle */
     int suspend_evtchn;
     int domid;
     unsigned int flags;
@@ -183,13 +183,12 @@ main(int argc, char **argv)
     max_f = atoi(argv[4]);
     si.flags = atoi(argv[5]);
 
-    si.suspend_evtchn = si.xce = -1;
+    si.suspend_evtchn = -1;
 
-    si.xce = xc_evtchn_open();
-    if (si.xce < 0)
+    si.xce = xc_evtchn_open(NULL, 0);
+    if (si.xce == NULL)
         warnx("failed to open event channel handle");
-
-    if (si.xce > 0)
+    else
     {
         port = xs_suspend_evtchn_port(si.domid);
 
index 478fac2bcb9a61eee09784eb2bd8393c574042be..985f1dd12354cb1fb96278010413573ee17b58c9 100644 (file)
@@ -268,7 +268,7 @@ static void log_event(int event_id)
 }
 
 int virq_port;
-int xce_handle = -1;
+xc_evtchn *xce_handle = NULL;
 
 /* Returns the event channel handle. */
 /* Stolen from xenstore code */
@@ -280,16 +280,16 @@ static int eventchn_init(void)
     if (0)
         return -1;
   
-    xce_handle = xc_evtchn_open();
+    xce_handle = xc_evtchn_open(NULL, 0);
 
-    if (xce_handle < 0)
+    if (xce_handle == NULL)
         perror("Failed to open evtchn device");
   
     if ((rc = xc_evtchn_bind_virq(xce_handle, VIRQ_TBUF)) == -1)
         perror("Failed to bind to domain exception virq port");
     virq_port = rc;
   
-    return xce_handle;
+    return xce_handle == NULL ? -1 : 0;
 }
 
 static void wait_for_event(void)
@@ -300,7 +300,7 @@ static void wait_for_event(void)
     struct timeval tv;
     int evtchn_fd;
   
-    if (xce_handle < 0) {
+    if (xce_handle == NULL) {
         nanosleep(&opts.poll_sleep, NULL);
         return;
     }
index 9f7bdf008a584202a4e2c7ee0685cb7c44d08ebe..807b21816b77c18ced94309ebd196996aa47e157 100644 (file)
@@ -40,7 +40,7 @@
 
 typedef struct mem_event {
     domid_t domain_id;
-    int xce_handle;
+    xc_evtchn *xce_handle;
     int port;
     mem_event_back_ring_t back_ring;
     mem_event_shared_page_t *shared_page;
index ea32407ca4ec3d3e6ef5ff8eeefc9bd203a92f79..e1e727991d8a0e2a9004d92e91ffb991d2bc35a3 100644 (file)
@@ -70,7 +70,7 @@ int policy_init(xenpaging_t *paging)
 int policy_choose_victim(xenpaging_t *paging, domid_t domain_id,
                          xenpaging_victim_t *victim)
 {
-    struct xc_interface *xch = paging->xc_handle;
+    xc_interface *xch = paging->xc_handle;
     unsigned long wrap = current_gfn;
     ASSERT(victim != NULL);
 
index 3b9c836aa0959aed3b93c8038da3f59ab8f31606..d1a62ff77f96aac1535f7fb54beb66eeb07d86c1 100644 (file)
@@ -65,9 +65,9 @@ int xc_mem_paging_flush_ioemu_cache(domid_t domain_id)
     return rc;
 }
 
-int xc_wait_for_event_or_timeout(xc_interface *xch, int xce_handle, unsigned long ms)
+int xc_wait_for_event_or_timeout(xc_interface *xch, xc_evtchn *xce, unsigned long ms)
 {
-    struct pollfd fd = { .fd = xce_handle, .events = POLLIN | POLLERR };
+    struct pollfd fd = { .fd = xc_evtchn_fd(xce), .events = POLLIN | POLLERR };
     int port;
     int rc;
     
@@ -83,14 +83,14 @@ int xc_wait_for_event_or_timeout(xc_interface *xch, int xce_handle, unsigned lon
     
     if ( rc == 1 )
     {
-        port = xc_evtchn_pending(xce_handle);
+        port = xc_evtchn_pending(xce);
         if ( port == -1 )
         {
             ERROR("Failed to read port from event channel");
             goto err;
         }
         
-        rc = xc_evtchn_unmask(xce_handle, port);
+        rc = xc_evtchn_unmask(xce, port);
         if ( rc != 0 )
         {
             ERROR("Failed to unmask event channel port");
@@ -106,9 +106,9 @@ int xc_wait_for_event_or_timeout(xc_interface *xch, int xce_handle, unsigned lon
     return -errno;
 }
 
-int xc_wait_for_event(xc_interface *xch, int xce_handle)
+int xc_wait_for_event(xc_interface *xch, xc_evtchn *xce)
 {
-    return xc_wait_for_event_or_timeout(xch, xce_handle, -1);
+    return xc_wait_for_event_or_timeout(xch, xce, -1);
 }
 
 int xc_get_platform_info(xc_interface *xc_handle, domid_t domain_id,
index 5febb89ef32a569eff652222ab70277c97c405bd..41cf310c476668e785fa36a9e2b00d5dffc6fd7d 100644 (file)
@@ -53,8 +53,8 @@ typedef struct xc_platform_info {
 int alloc_bitmap(unsigned long **bitmap, unsigned long bitmap_size);
 
 int xc_mem_paging_flush_ioemu_cache(domid_t domain_id);
-int xc_wait_for_event(xc_interface *xch, int xce_handle);
-int xc_wait_for_event_or_timeout(xc_interface *xch, int xce_handle, unsigned long ms);
+int xc_wait_for_event(xc_interface *xch, xc_evtchn *xce);
+int xc_wait_for_event_or_timeout(xc_interface *xch, xc_evtchn *xce, unsigned long ms);
 
 int xc_get_platform_info(xc_interface *xc_handle, domid_t domain_id,
                          xc_platform_info_t *platform_info);
index 74e4f565895039050e1f75682cb40b5d1a95cf19..508068f9c59c0b36090b65bef3f0c2dcdd64051b 100644 (file)
@@ -144,8 +144,8 @@ xenpaging_t *xenpaging_init(domid_t domain_id)
     }
 
     /* Open event channel */
-    paging->mem_event.xce_handle = xc_evtchn_open();
-    if ( paging->mem_event.xce_handle < 0 )
+    paging->mem_event.xce_handle = xc_evtchn_open(NULL, 0);
+    if ( paging->mem_event.xce_handle == NULL )
     {
         ERROR("Failed to open event channel");
         goto err;
@@ -246,7 +246,7 @@ xenpaging_t *xenpaging_init(domid_t domain_id)
 int xenpaging_teardown(xenpaging_t *paging)
 {
     int rc;
-    struct xc_interface *xch;
+    xc_interface *xch;
 
     if ( paging == NULL )
         return 0;
@@ -274,7 +274,7 @@ int xenpaging_teardown(xenpaging_t *paging)
     {
         ERROR("Error closing event channel");
     }
-    paging->mem_event.xce_handle = -1;
+    paging->mem_event.xce_handle = NULL;
     
     /* Close connection to Xen */
     rc = xc_interface_close(xch);
@@ -338,7 +338,7 @@ static int put_response(mem_event_t *mem_event, mem_event_response_t *rsp)
 int xenpaging_evict_page(xenpaging_t *paging,
                          xenpaging_victim_t *victim, int fd, int i)
 {
-    struct xc_interface *xch = paging->xc_handle;
+    xc_interface *xch = paging->xc_handle;
     void *page;
     unsigned long gfn;
     int ret;
@@ -412,7 +412,7 @@ static int xenpaging_resume_page(xenpaging_t *paging, mem_event_response_t *rsp,
 static int xenpaging_populate_page(xenpaging_t *paging,
     uint64_t *gfn, int fd, int i)
 {
-    struct xc_interface *xch = paging->xc_handle;
+    xc_interface *xch = paging->xc_handle;
     unsigned long _gfn;
     void *page;
     int ret;
@@ -467,7 +467,7 @@ static int xenpaging_populate_page(xenpaging_t *paging,
 static int evict_victim(xenpaging_t *paging, domid_t domain_id,
                         xenpaging_victim_t *victim, int fd, int i)
 {
-    struct xc_interface *xch = paging->xc_handle;
+    xc_interface *xch = paging->xc_handle;
     int j = 0;
     int ret;
 
index b043ac45f849b926d8c55927bc964a6fe63bd991..1749740482458704737a0b3a5d81275d62eec1c0 100644 (file)
@@ -52,7 +52,7 @@
 
 #include "hashtable.h"
 
-extern int xce_handle; /* in xenstored_domain.c */
+extern xc_evtchn *xce_handle; /* in xenstored_domain.c */
 
 static bool verbose = false;
 LIST_HEAD(connections);
@@ -323,7 +323,7 @@ static int initialize_set(fd_set *inset, fd_set *outset, int sock, int ro_sock,
        set_fd(ro_sock,            inset, &max);
        set_fd(reopen_log_pipe[0], inset, &max);
 
-       if (xce_handle != -1)
+       if (xce_handle != NULL)
                set_fd(xc_evtchn_fd(xce_handle), inset, &max);
 
        list_for_each_entry(conn, &connections, list) {
@@ -1901,7 +1901,7 @@ int main(int argc, char *argv[])
 
        signal(SIGHUP, trigger_reopen_log);
 
-       if (xce_handle != -1)
+       if (xce_handle != NULL)
                evtchn_fd = xc_evtchn_fd(xce_handle);
 
        /* Get ready to listen to the tools. */
index 7aa87cd022ebff9a40928838d17b096af33c1b8f..654185d4bb5b2212b391020d3bd52ccd76d3c33e 100644 (file)
@@ -36,7 +36,7 @@
 static xc_interface **xc_handle;
 static evtchn_port_t virq_port;
 
-int xce_handle = -1; 
+xc_evtchn *xce_handle = NULL;
 
 struct domain
 {
@@ -580,8 +580,7 @@ static int dom0_init(void)
        return 0; 
 }
 
-/* Returns the event channel handle. */
-int domain_init(void)
+void domain_init(void)
 {
        int rc;
 
@@ -595,9 +594,9 @@ int domain_init(void)
 
        talloc_set_destructor(xc_handle, close_xc_handle);
 
-       xce_handle = xc_evtchn_open();
+       xce_handle = xc_evtchn_open(NULL, 0);
 
-       if (xce_handle < 0)
+       if (xce_handle == NULL)
                barf_perror("Failed to open evtchn device");
 
        if (dom0_init() != 0) 
@@ -606,8 +605,6 @@ int domain_init(void)
        if ((rc = xc_evtchn_bind_virq(xce_handle, VIRQ_DOM_EXC)) == -1)
                barf_perror("Failed to bind to domain exception virq port");
        virq_port = rc;
-
-       return xce_handle;
 }
 
 void domain_entry_inc(struct connection *conn, struct node *node)
index f42a9f50adad9d03f5d5d38a74c40a1429ff2edf..6a1e8be09b05d4fb7573042b1e0fa44769343d0d 100644 (file)
@@ -40,8 +40,7 @@ void do_set_target(struct connection *conn, struct buffered_data *in);
 /* domid */
 void do_get_domain_path(struct connection *conn, const char *domid_str);
 
-/* Returns the event channel handle */
-int domain_init(void);
+void domain_init(void);
 
 /* Returns the implicit path of a connection (only domains have this) */
 const char *get_implicit_path(const struct connection *conn);
index 9e07f3f2c4c3c571a3f2a6da271d10cc07dbb3d4..e380531e35a7ee891f8f8250b806a3f7d862c5af 100644 (file)
@@ -73,7 +73,7 @@ settings_t opts;
 int interrupted = 0; /* gets set if we get a SIGHUP */
 
 static xc_interface *xc_handle;
-static int event_fd = -1;
+static xc_evtchn *xce_handle = NULL;
 static int virq_port = -1;
 static int outfd = 1;
 
@@ -576,14 +576,13 @@ static void event_init(void)
 {
     int rc;
 
-    rc = xc_evtchn_open();
-    if (rc < 0) {
+    xce_handle = xc_evtchn_open(NULL, 0);
+    if (xce_handle == NULL) {
         perror("event channel open");
         exit(EXIT_FAILURE);
     }
-    event_fd = rc;
 
-    rc = xc_evtchn_bind_virq(event_fd, VIRQ_TBUF);
+    rc = xc_evtchn_bind_virq(xce_handle, VIRQ_TBUF);
     if (rc == -1) {
         PERROR("failed to bind to VIRQ port");
         exit(EXIT_FAILURE);
@@ -598,7 +597,7 @@ static void event_init(void)
 static void wait_for_event_or_timeout(unsigned long milliseconds)
 {
     int rc;
-    struct pollfd fd = { .fd = event_fd,
+    struct pollfd fd = { .fd = xc_evtchn_fd(xce_handle),
                          .events = POLLIN | POLLERR };
     int port;
 
@@ -611,7 +610,7 @@ static void wait_for_event_or_timeout(unsigned long milliseconds)
     }
 
     if (rc == 1) {
-        port = xc_evtchn_pending(event_fd);
+        port = xc_evtchn_pending(xce_handle);
         if (port == -1) {
             PERROR("failed to read port from evtchn");
             exit(EXIT_FAILURE);
@@ -622,7 +621,7 @@ static void wait_for_event_or_timeout(unsigned long milliseconds)
                     port, virq_port);
             exit(EXIT_FAILURE);
         }
-        rc = xc_evtchn_unmask(event_fd, port);
+        rc = xc_evtchn_unmask(xce_handle, port);
         if (rc == -1) {
             PERROR("failed to write port to evtchn");
             exit(EXIT_FAILURE);